import { android_get_report_show_info, android_get_report_detail_info } from "./report_manager_android.js"
import { openharmony_get_report_show_info, openharmony_get_report_detail_info } from "./report_manager_openharmony.js"

const fs = window.require('fs');

function get_report_platform(path) {
    let android_check_file = path + '/system_data';
    try {
        fs.accessSync(android_check_file, fs.constants.R_OK);
        return 'Android';
    } catch(err) {
        return 'OpenHarmony';
    }
}

export function get_report_detail_info(path) {
    let report_detail = {
        start_time: 0,
        is_big_endian: false,
        data_offset: 0,
        data_block_num: 0,
        data_mask: 0,

        fps_target: 0,
        fps: [],
        fps_average: 0,
        fps_jank: 0,
        fps_big_jank: 0,
        fps_max_frame_time: 0,
        fps_frame_time: [],

        cpu_cluster_num: 0,
        cpu_core_num: 0,
        cpu_index: [],
        cpu_max_freq: [],
        cpu_min_freq: [],
        cpu_freq: [],
        cpu_usage: [],
        cpu_average_usage: [],
        cpu_high_load: [],

        gpu_freq: [],
        gpu_max_freq: 0,
        gpu_min_freq: 0,
        gpu_average_freq: 0,
        gpu_high_freq_percent: 0,

        memory_use_max: 0,
        memory_use_min: 0,
        ddr_max_freq: 0,
        ddr_min_freq: 0,
        ddr_average_freq: 0,

        temp: [],
        temp_max: 0,
        temp_min: 1000,
        temp_average: 0,
        temp_high_percent: 0,

        power_max: 0,
        power_min: 0,
        power_average: 0,
        power_high_percent: 0,

        net_band_max: 0,
        net_band_min: 0,
        net_band_average: 0,
    };

    if (get_report_platform(path) === 'Android') {
        android_get_report_detail_info(path, report_detail);
    }

    if (get_report_platform(path) === 'OpenHarmony') {
        openharmony_get_report_detail_info(path, report_detail);
    }

    return report_detail;
}

export function get_report_show_info(path) {
    if (get_report_platform(path) === 'Android') {
        return android_get_report_show_info(path);
    }

    if (get_report_platform(path) === 'OpenHarmony') {
        return openharmony_get_report_show_info(path);
    }
}